package HomeWork;
/*
定义方法，计算出数组中的最大值和最小值。数组: int[] arr = {1,43,43,5,4,6,7,7,88,0,9};
 */
public class Code6 {
    public static void main(String[] args) {
        int[] arr = {1,43,43,5,4,6,7,7,88,0,9};

        int max = getMax(arr);
        int min = getMin(arr);

        System.out.println("数组中最大值为："+max);
        System.out.println("数组中最小值为："+min);
    }

    public static int getMax(int[] arr){
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(max < arr[i]){
                max = arr[i];
            }
        }
        return max;
    }

    public static int getMin(int[] arr){
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(min > arr[i]){
                min = arr[i];
            }
        }
        return min;
    }
}
